/**
 * Created by Administrator on 2016/4/24.
 */
function change() {
    resetForm();
    var isTure = 0;
    var one = "";
    var two = "";
    var email = "";
    var four = "";
    var five ="";
    one = document.getElementById("txt_one").value;
    two = document.getElementById("txt_two").value;
    email = document.getElementById("txt_three").value;
    four = document.getElementById("txt_four").value;
    five = document.getElementById("txt_five").value;
    var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    var pattern=/^\d+(\.\d+)?$/;
    var flag = pattern.test(four);
    var mob =/^1\d{10}$/;
    var mobile = mob.test(five);
    if (one.length == 0) {
        $("#headErr").html("请输入姓名");
    }
    else {
        if(document.getElementById("txt_one").value.length>5 || document.getElementById("txt_one").value.length < 1){
            $("#headErr").html("您输入的不符合要求");
        }else{
            isTure++;
        }
    }
    if (two.length == 0) {
        $("#titleErr").html("请输入内容");
    }
    else {
        if(document.getElementById("txt_two").value.length>600 || document.getElementById("txt_two").value.length<10){
            $("#titleErr").html("请按照提示输入");
        }else{
            isTure ++;
        }
    }
    if(email.length ==0){
        $("#emailErr").html("请输入电子邮件");
    }
    else{
        if(!reg.test(document.getElementById("txt_three").value)){
            $("#emailErr").html("您输入的邮箱格式不正确");
        }else{
            isTure ++;
        }
    }
    if(!flag){
        $("#qqErr").html("请输入QQ号码");
    }
    else{
        if(document.getElementById("txt_four").value.length>10 || document.getElementById("txt_four").value.length < 6){
            $("#qqErr").html("请重新输入qq号码");
        }else{
            isTure ++;
        }
    }
    if(five.length ==0){
        $("#mobileErr").html("请输入手机号码");
    }
    else{
        if(!mob.test(document.getElementById("txt_five").value)){
            $("#mobileErr").html("您输入的手机号码不正确");
        }else{
            isTure ++;
        }
    }


    if(isTure == 5) {
        //$("#form").submit(alert(document.getElementById("success").innerHTML))
        $.post("data/data.json",$("#form").serialize(),
         function(data){
         if(1) {
             $("#success").css({'display':'block'})
             //alert(data.code)
         }
          else {
            alert(data.message)
         }
         }, "json");
        //$("#submit").click(function(){
        //    $.ajax({
        //        url:'',
        //        type:"POST",
        //        data:$('#form').serialize(),
        //        success: $("#success").css({'display':'block'})
        //    });
        //});
    }
}
function head_one() {
    var one = $("#txt_one").val();
    if (one.length == 0) {
        $("#headErr").html("请输入姓名");
    }
    else {
        if(document.getElementById("txt_one").value.length>5 || document.getElementById("txt_one").value.length < 1){
            $("#headErr").html("您输入的不符合要求");
        }else{
        }
    }
}
function head_two(){
    $("#headErr").html("");
}
function title_one(){
    var two = $("#txt_two").val();
    if (two.length == 0) {
        $("#titleErr").html("请输入内容");
    }
    else {
        if(document.getElementById("txt_two").value.length>600 || document.getElementById("txt_two").value.length<10){
            $("#titleErr").html("请按照提示输入");
        }else{
        }
    }
}
function title_two(){
    $("#titleErr").html("");
}

function email_one(){
    var three = $("#txt_three").val();
    var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if(three.length ==0){
        $("#emailErr").html("请输入电子邮件");
    }
    else{
        if(!reg.test(document.getElementById("txt_three").value)){
            $("#emailErr").html("您输入的邮箱格式不正确");
        }else{
        }
    }
}
function email_two(){
    $("#emailErr").html("");
}

function qq_one(){
    var four = $("#txt_four").val();
    var pattern=/^\d+(\.\d+)?$/;
    var flag = pattern.test(four);
    if(!flag){
        $("#qqErr").html("请输入QQ号码");
    }
    else{
        if(document.getElementById("txt_four").value.length>10 || document.getElementById("txt_four").value.length < 6){
            $("#qqErr").html("请重新输入qq号码");
        }else{
        }
    }
}
function qq_two(){
    $("#qqErr").html("");
}

function mobile_one(){
    var five = $("#txt_five").val();
    var mob =/^1\d{10}$/;
    if(five.length ==0){
        $("#mobileErr").html("请输入手机号码");
    }
    else{
        if(!mob.test(document.getElementById("txt_five").value)){
            $("#mobileErr").html("手机号码不正确");
        }else{
        }
    }
}
function mobile_two(){
    $("#mobileErr").html("");
}






function resetForm() {
    $("#headErr").html("");
    $("#titleErr").html("");
    $("#emailErr").html("");
    $("#qqErr").html("");
    $("#mobileErr").html("");
}